<?php
namespace app\admin\controller;


use app\common\controller\Base;
use app\common\model\Config as ConfigModel;
use app\common\tool\Tool;
use think\Request;


class Banner extends Base{

    public function index(){

    }

    /**
     * 系统设置
     */
    public function sysConfig(){

        $configs = ConfigModel::all();

        $configs = collection($configs)->toArray();
        $configs = Tool::changeArrayKey($configs,'ckey');


        return view('',['configs'=>$configs]);
    }


    public function update(Request $request){

        if(!$request->isPost()){
            $this->error("非法操作");
        }

        $configModel = new ConfigModel();

        $data = $request->param();
        //var_dump($data);exit;
        foreach($data as $key => $val ){
            $config = $configModel->where('ckey',$key)->find();
            if(!$config) {
                $configModel->data(['ckey'=>$key,'cvalue'=>$val],true)->isUpdate(false)->save();
            }else {
                $config->save(['cvalue'=>$val]);
            }
        }

        $this->success('设置成功');
    }


    public function indexbanner(){
        $configs = ConfigModel::all();

        $configs = collection($configs)->toArray();
        $configs = Tool::changeArrayKey($configs,'ckey');


        return view('',['configs'=>$configs]);
    }


}